capture log close
clear all
set more off
pause off
# delimit;

local output "";
local log "";
local data "";

/* 
Create Figure A2
*/

foreach set in earn10yr earn55 {;

use "`data'\collapse_cumlf_`set'_dod.dta", clear;

/* Reshape for plot */
reshape long
	n_anyearn_ n_phusanyyr_
	, i(ser_dobyy) j(year);
rename n_anyearn_ n_anyearn_`set';
rename n_phusanyyr_ n_phusanyyr_`set';
	
/* Age */
gen age=year-ser_dobyy;
tempfile cumlf_`set';
save `cumlf_`set'';
};

merge 1:1 ser_dobyy year using `cumlf_earn10yr';

preserve ;

/* ***************************************************** */
/* **** PLOT RETIREMENT AND CLAIMING ACROSS COHORTS **** */
/* ***************************************************** */

keep if age>=55 & age<=69 ;

foreach set in earn10yr {;
twoway 	
	connected n_anyearn_`set' age if ser_dobyy==1937 & age>=55 & age<=69, lcolor(orange*2) lwidth(medthick) lpattern(solid) mcolor(orange*2) msymbol(T) ||
	connected n_phusanyyr_`set' age if ser_dobyy==1937 & age>=55 & age<=69, lcolor(blue*2) lwidth(medthick) lpattern(solid) mcolor(blue*2) msymbol(Th) ||
	connected n_anyearn_`set' age if ser_dobyy==1943 & age>=55 & age<=69, lcolor(orange*.5) lwidth(medthick) lpattern(solid) mcolor(orange*.5) msymbol(S) ||
	connected n_phusanyyr_`set' age if ser_dobyy==1943 & age>=55 & age<=69, lcolor(blue*.25) lwidth(medthick) lpattern(solid) mcolor(blue*.25) msymbol(Sh) 
	xtitle("Age", size(medsmall)) xsc(r(55 69)) xlab(55(1)69)
	ytitle("Fraction of birth cohort", size(medsmall)) ysc(r(0 1)) ylab(0(.2)1)
	legend(col(2) row(2) label(1 "YOB1937, working") label(2 "YOB1937, claiming") label(3 "YOB1943, working") label(4 "YOB1943, claiming"))
	graphregion(color(white))
	bgcolor(white)
	ylabel(,nogrid)
	xline(62, lcolor(gray) lpattern(dash))
	xline(65, lcolor(gray) lpattern(dash))
	;
	graph export "`output'\\Figure_A2A.png", replace;
};

foreach set in earn10yr {;
twoway 	
	connected n_phusanyyr_`set' age if ser_dobyy==1935 & age>=55 & age<=69, lcolor(blue*2) lwidth(medthick) lpattern(solid) mcolor(blue*2) msymbol(T) ||
	connected n_phusanyyr_`set' age if ser_dobyy==1936 & age>=55 & age<=69, lcolor(blue) lwidth(medthick) lpattern(solid) mcolor(blue) msymbol(Th) ||
	connected n_phusanyyr_`set' age if ser_dobyy==1937 & age>=55 & age<=69, lcolor(blue*.5) lwidth(medthick) lpattern(solid) mcolor(blue*.5) msymbol(t) ||
	connected n_phusanyyr_`set' age if ser_dobyy==1938 & age>=55 & age<=69, lcolor(orange*2) lwidth(medthick) lpattern(longdash) mcolor(orange*2) msymbol(O) ||
	connected n_phusanyyr_`set' age if ser_dobyy==1939 & age>=55 & age<=69, lcolor(orange*1.5) lwidth(medthick) lpattern(longdash) mcolor(orange*1.5) msymbol(Oh) ||
	connected n_phusanyyr_`set' age if ser_dobyy==1940 & age>=55 & age<=69, lcolor(orange) lwidth(medthick) lpattern(longdash) mcolor(orange) msymbol(o) ||
	connected n_phusanyyr_`set' age if ser_dobyy==1941 & age>=55 & age<=69, lcolor(orange*.5) lwidth(medthick) lpattern(longdash) mcolor(orange*.5) msymbol(oh) ||
	connected n_phusanyyr_`set' age if ser_dobyy==1942 & age>=55 & age<=69, lcolor(orange*.25) lwidth(medthick) lpattern(shortdash) mcolor(orange*.25) msymbol(S) ||
	connected n_phusanyyr_`set' age if ser_dobyy==1943 & age>=55 & age<=69, lcolor(green) lwidth(medthick) lpattern(shortdash) mcolor(green) msymbol(Sh) ||
	connected n_phusanyyr_`set' age if ser_dobyy==1944 & age>=55 & age<=69, lcolor(green*.5) lwidth(medthick) lpattern(shortdash) mcolor(green*.5) msymbol(s) ||
	connected n_phusanyyr_`set' age if ser_dobyy==1945 & age>=55 & age<=69, lcolor(green*.25) lwidth(medthick) lpattern(shortdash) mcolor(green*.25) msymbol(sh)
	xtitle("Age", size(medsmall)) xsc(r(55 69)) xlab(55(1)69)
	ytitle("Fraction of birth cohort", size(medsmall)) ysc(r(0 1)) ylab(0(.2)1)
	legend(col(4) row(3) 
		label(1 "YOB1935") label(2 "YOB1936") label(3 "YOB1937") label(4 "YOB1938") label(5 "YOB1939") 
		label(6 "YOB1940") label(7 "YOB1941") label(8 "YOB1942") label(9 "YOB1943") label(10 "YOB1944") label(11 "YOB1945"))	graphregion(color(white))
	bgcolor(white)
	ylabel(,nogrid)
	xline(62, lcolor(gray) lpattern(dash))
	xline(65, lcolor(gray) lpattern(dash))
	xline(66, lcolor(gray) lpattern(dash))
	;
	graph export "`output'\\Figure_A2B.png", replace;
};

foreach set in earn10yr {;
twoway 	
	connected n_anyearn_`set' age if ser_dobyy==1935 & age>=55 & age<=69, lcolor(blue*2) lwidth(medthick) lpattern(solid) mcolor(blue*2) msymbol(T) ||
	connected n_anyearn_`set' age if ser_dobyy==1936 & age>=55 & age<=69, lcolor(blue) lwidth(medthick) lpattern(solid) mcolor(blue) msymbol(Th) ||
	connected n_anyearn_`set' age if ser_dobyy==1937 & age>=55 & age<=69, lcolor(blue*.5) lwidth(medthick) lpattern(solid) mcolor(blue*.5) msymbol(t) ||
	connected n_anyearn_`set' age if ser_dobyy==1938 & age>=55 & age<=69, lcolor(orange*2) lwidth(medthick) lpattern(longdash) mcolor(orange*2) msymbol(O) ||
	connected n_anyearn_`set' age if ser_dobyy==1939 & age>=55 & age<=69, lcolor(orange*1.5) lwidth(medthick) lpattern(longdash) mcolor(orange*1.5) msymbol(Oh) ||
	connected n_anyearn_`set' age if ser_dobyy==1940 & age>=55 & age<=69, lcolor(orange) lwidth(medthick) lpattern(longdash) mcolor(orange) msymbol(o) ||
	connected n_anyearn_`set' age if ser_dobyy==1941 & age>=55 & age<=69, lcolor(orange*.5) lwidth(medthick) lpattern(longdash) mcolor(orange*.5) msymbol(oh) ||
	connected n_anyearn_`set' age if ser_dobyy==1942 & age>=55 & age<=69, lcolor(orange*.25) lwidth(medthick) lpattern(shortdash) mcolor(orange*.25) msymbol(S) ||
	connected n_anyearn_`set' age if ser_dobyy==1943 & age>=55 & age<=69, lcolor(green) lwidth(medthick) lpattern(shortdash) mcolor(green) msymbol(Sh) ||
	connected n_anyearn_`set' age if ser_dobyy==1944 & age>=55 & age<=69, lcolor(green*.5) lwidth(medthick) lpattern(shortdash) mcolor(green*.5) msymbol(s) ||
	connected n_anyearn_`set' age if ser_dobyy==1945 & age>=55 & age<=69, lcolor(green*.25) lwidth(medthick) lpattern(shortdash) mcolor(green*.25) msymbol(sh)
	xtitle("Age", size(medsmall)) xsc(r(55 69)) xlab(55(1)69)
	ytitle("Fraction of birth cohort", size(medsmall)) ysc(r(0 1)) ylab(0(.2)1)
	legend(col(4) row(3) 
		label(1 "YOB1935") label(2 "YOB1936") label(3 "YOB1937") label(4 "YOB1938") label(5 "YOB1939") 
		label(6 "YOB1940") label(7 "YOB1941") label(8 "YOB1942") label(9 "YOB1943") label(10 "YOB1944") label(11 "YOB1945"))
	graphregion(color(white))
	bgcolor(white)
	ylabel(,nogrid)
	xline(62, lcolor(gray) lpattern(dash))
	xline(65, lcolor(gray) lpattern(dash))
	xline(66, lcolor(gray) lpattern(dash))
	;
	graph export "`output'\\Figure_A2C.png", replace;
};

